package com.seadragon.app.ksr.extractor;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service("streetNumberExtractor")
public class StreetNumberExtractor implements Extractor {
	private Logger logger = LoggerFactory.getLogger(StreetNumberExtractor.class);
	private static final String STREET_NUMBER_PATTERN = "^([A-Z]+)?([0-9]+)([A-Z]+)?([ ]*-[ ]*([A-Z]+)?([0-9]+)([A-Z]+)?)?";

	/* (non-Javadoc)
	 * @see com.seadragon.app.ksr.extractor.Extractor#extract(java.lang.String)
	 */
	@Override
	public String extract(String addressLine1) {
		logger.info("Address Line 1: " + addressLine1);
		Pattern p = Pattern.compile(STREET_NUMBER_PATTERN);
		Matcher m = p.matcher(addressLine1);
		String streetNumber = null;
		while (m.find()) {
			streetNumber = m.group();
//			streetNumber = streetNumber.replaceAll(" ", "");
			logger.info("The street number is " + streetNumber);
		}
		return streetNumber.toUpperCase();
	}
}
